/****************************************************************
 * Fulguro
 * Copyright (C) 2004 Christophe Clienti
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 ***************************************************************/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <flgrCoreData.h>
#include <flgrCoreNhbManage.h>
#include <flgrCoreDispatch.h>
#include <flgrCoreSlideWindow.h>
#include <flgrMorphoKerOp.h>
#include "flgrMorphoHoM.h"

/*!
 * \addtogroup group_fulguro_core_morpho_hom
 * @{
 */


void flgr2d_hit_or_miss_fgBIT(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  flgr_no_define_type_function(FLGR_BIT);
}
void flgr2d_hit_or_miss_fgUINT8(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgUINT8(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_hit_or_miss_fgUINT8);
}
void flgr2d_hit_or_miss_fgUINT16(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgUINT16(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_hit_or_miss_fgUINT16);
}
void flgr2d_hit_or_miss_fgUINT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgUINT32(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_hit_or_miss_fgUINT32);
}
void flgr2d_hit_or_miss_fgINT8(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgINT8(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_hit_or_miss_fgINT8);
}
void flgr2d_hit_or_miss_fgINT16(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgINT16(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_hit_or_miss_fgINT16);
}
void flgr2d_hit_or_miss_fgINT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgINT32(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_hit_or_miss_fgINT32);
}
void flgr2d_hit_or_miss_fgFLOAT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgFLOAT32(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_hit_or_miss_fgFLOAT32);
}
void flgr2d_hit_or_miss_fgFLOAT64(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgFLOAT64(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_hit_or_miss_fgFLOAT64);
}

////////////////////////////////////////////////////////////////////////////
/*! Hit or miss transformation for binary image (0, 1..255)
 *  @param imgdest : pointer to FLGR_Data2D
 *  @param imgsrc : pointer to FLGR_Data2D
 *  @param nhb : pointer to FLGR_Data2D containing a golay letter \sa flgr2d_fill_nhb_golay
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_hit_or_miss(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_Ret ret;

  FLGR_DECLARE_FUNCTION;

  if((imgdest==NULL) || (imgsrc==NULL) ||(nhb==NULL)){
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if((ret=flgr2d_is_data_same_attributes(imgdest,imgsrc,__FUNCTION__))!=FLGR_RET_OK) return ret;
  if((ret=flgr2d_is_data_same_type(imgdest,nhb))!=FLGR_RET_OK) return ret;


  FLGR_DISPATCH_PROCEDURE(imgdest->type,flgr2d_hit_or_miss,imgdest,imgsrc,nhb);

}




void flgr2d_thinning_fgBIT(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  flgr_no_define_type_function(FLGR_BIT);
}
void flgr2d_thinning_fgUINT8(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgUINT8(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thinning_fgUINT8);
}
void flgr2d_thinning_fgUINT16(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgUINT16(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thinning_fgUINT16);
}
void flgr2d_thinning_fgUINT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgUINT32(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thinning_fgUINT32);
}
void flgr2d_thinning_fgINT8(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgINT8(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thinning_fgINT8);
}
void flgr2d_thinning_fgINT16(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgINT16(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thinning_fgINT16);
}
void flgr2d_thinning_fgINT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgINT32(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thinning_fgINT32);
}
void flgr2d_thinning_fgFLOAT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgFLOAT32(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thinning_fgFLOAT32);
}
void flgr2d_thinning_fgFLOAT64(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgFLOAT64(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thinning_fgFLOAT64);
}


////////////////////////////////////////////////////////////////////////////
/*! Thinning transformation for binary image (0, 1..255)
 *  @param imgdest : pointer to FLGR_Data2D
 *  @param imgsrc : pointer to FLGR_Data2D
 *  @param nhb : pointer to FLGR_Data2D containing a golay letter \sa flgr2d_fill_nhb_golay
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_thinning(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_Ret ret;

  FLGR_DECLARE_FUNCTION;

  if((imgdest==NULL) || (imgsrc==NULL) ||(nhb==NULL)){
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if((ret=flgr2d_is_data_same_attributes(imgdest,imgsrc,__FUNCTION__))!=FLGR_RET_OK) return ret;
  if((ret=flgr2d_is_data_same_type(imgdest,nhb))!=FLGR_RET_OK) return ret;

  FLGR_DISPATCH_PROCEDURE(imgdest->type,flgr2d_thinning,imgdest,imgsrc,nhb);

}






void flgr2d_thickening_fgBIT(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  flgr_no_define_type_function(FLGR_BIT);
}
void flgr2d_thickening_fgUINT8(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgUINT8(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thickening_fgUINT8);
}
void flgr2d_thickening_fgUINT16(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgUINT16(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thickening_fgUINT16);
}
void flgr2d_thickening_fgUINT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgUINT32(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thickening_fgUINT32);
}
void flgr2d_thickening_fgINT8(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgINT8(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thickening_fgINT8);
}
void flgr2d_thickening_fgINT16(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgINT16(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thickening_fgINT16);
}
void flgr2d_thickening_fgINT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgINT32(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thickening_fgINT32);
}
void flgr2d_thickening_fgFLOAT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgFLOAT32(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thickening_fgFLOAT32);
}
void flgr2d_thickening_fgFLOAT64(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_raster_slide_window_fgFLOAT64(imgdest, imgsrc, nhb, FLGR_NHB_NO_SYM, flgr2d_get_nhb_thickening_fgFLOAT64);
}


////////////////////////////////////////////////////////////////////////////
/*! Thickening transformation for binary image (0, 1..255)
 *  @param imgdest : pointer to FLGR_Data2D
 *  @param imgsrc : pointer to FLGR_Data2D
 *  @param nhb : pointer to FLGR_Data2D containing a golay letter \sa flgr2d_fill_nhb_golay
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_thickening(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *nhb) {
  FLGR_Ret ret;

  FLGR_DECLARE_FUNCTION;

  if((imgdest==NULL) || (imgsrc==NULL) ||(nhb==NULL)){
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if((ret=flgr2d_is_data_same_attributes(imgdest,imgsrc,__FUNCTION__))!=FLGR_RET_OK) return ret;
  if((ret=flgr2d_is_data_same_type(imgdest,nhb))!=FLGR_RET_OK) return ret;

  FLGR_DISPATCH_PROCEDURE(imgdest->type,flgr2d_thickening,imgdest,imgsrc,nhb);

}




//! @}
